package com.qfedu.service.impl;

import com.qfedu.mapper.TaskplanMapper;
import com.qfedu.mapper.TaskplanMapper;
import com.qfedu.model.Taskplan;
import com.qfedu.model.Taskplan;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.TaskplanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class TaskplanServiceImpl implements TaskplanService {
    @Autowired
    private TaskplanMapper taskplanMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = taskplanMapper.count();
        pageResult.setTotal(count);
        List<Taskplan> page = taskplanMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addTaskplan(Taskplan taskplan) {
        taskplan.setUpdatetime(new Date());
        return taskplanMapper.addTaskplan(taskplan);
    }

    @Override
    public Taskplan findById(String tid) {
        return   taskplanMapper.findById(tid);
    }

    @Override
    public int editTaskplan(Taskplan taskplan) {
        taskplan.setUpdatetime(new Date());
        int i = taskplanMapper.editTaskplan(taskplan);
        return i;
    }

    @Override
    public int deleteByTid(String tid) {
        return taskplanMapper.deleteByTid(tid);
    }

    @Override
    public List<Taskplan> findByBid(String bid) {
        return taskplanMapper.findByBid(bid);

    }
}